package com.woniuxy.userassembly.apiimpl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.api.UserFinanceApi;
import com.woniuxy.common.PageResult;
import com.woniuxy.common.Result;
import com.woniuxy.form.UserFinanceForm;
import com.woniuxy.userassembly.model.UserCreditInfo;
import com.woniuxy.userassembly.model.UserFinance;
import com.woniuxy.userassembly.service.IUserFinanceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Liyfi
 * @since 2021-05-22
 */
@RestController
@Slf4j
public class UserFinanceController implements UserFinanceApi {
    @Autowired
    private IUserFinanceService service;

    @Override
    public Result addUserFinance(UserFinanceForm form) {

        log.info("添加充值记录,{}",form);
        UserFinance userFinance = new UserFinance();
        BeanUtils.copyProperties(form,userFinance);

        int i = service.addUserFinance(userFinance);
        if(i == 1){
            return Result.success("添加成功");
        }else {
            return Result.fail("添加失败");
        }
    }

    @Override
    public PageResult findUserFinance(int pageIndex) {
        Page<UserFinance> pageParam = new Page<>(pageIndex,10L);
        IPage<UserFinance> pageResult = service.page(pageParam);
        PageResult<UserFinance> myPageResult = new PageResult<UserFinance>((int) pageResult.getTotal(), (int) pageResult.getCurrent(), (int) pageResult.getSize(), pageResult.getRecords());
        myPageResult.setSuccess(true);
        return myPageResult;
    }
}

